﻿// -----------------------------------------------------------------------
// <copyright file="ServiceRegistrar.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ServiceModel;
using Caliburn.Micro;
using SS.Common.Utilities;
using SS.WPF.Framework.Localization;
using SS.WPF.Framework.Restriction;
using TestFramework.Common;

namespace TestFramework
{
    /// <summary>
    /// Register Services
    /// </summary>
    public static class ServiceRegistrar
    {
        public static void Register(CompositionContainer container)
        {
            RegisterWCFService(container);
            RegisterMultiLanguages(container);
            RegisterRestriction(container);
        }

        public static void RegisterWCFService(CompositionContainer container)
        {
            var channelFactory = new ChannelFactory<ITaskManagerService>("DemoServiceEndpoint");
            var proxy = channelFactory.CreateChannel();
            container.ComposeExportedValue<ITaskManagerService>(proxy);
        }

        public static void RegisterMultiLanguages(CompositionContainer container)
        {
            var lang = PathHelper.GetAppPath(@"Config\Languages.xml");
            var transProvider = new XmlTranslationProvider(lang);
            transProvider.Initialize();

            var transManager = new TranslationManager
                                       {
                                           TranslationProvider = transProvider
                                       };
            container.ComposeExportedValue<TranslationManager>(transManager);
        }

        public static void RegisterRestriction(CompositionContainer container)
        {
            try
            {
                IRestrictionDictionary xmlSchemasService = new RestrictionDictionary();
                xmlSchemasService.Initialize("TestFramework.Config.EFPConfigurationFile.xsd");
                container.ComposeExportedValue<IRestrictionDictionary>(xmlSchemasService);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
    }
}
